const HtmlWebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");

const defaultConfig = {
  mode: "development",
  entry: "./src/main.ts",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader",
        options: {
          transpileOnly: true,
        },
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".js", ".json"],
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      inject: true,
      template: "./public/index.html",
    }),
  ],
  externals: {
    jquery: "jQuery",
  },
  devServer: {
    client: {
      overlay: false,
    },
    headers: { "Access-Control-Allow-Origin": "*" },
    historyApiFallback: true,
    hot: true,
    proxy: {
      "/api/weather": {
        target: "http://www.weather.com.cn",
        changeOrigin: true,
        pathRewrite: { "/api/weather": "" },
      },
      "/api/flash": {
        target: "http://flash.weather.com.cn",
        changeOrigin: true,
        pathRewrite: { "/api/flash": "" },
      },
    },
    static: {
      // 静态内容的目录，等同于 webpack4的 devServer.conentBase
      directory: "./public",
      // 通过网络访问开发服务器静态内容的 url
      publicPath: "/",
    },
  },
};

module.exports = defaultConfig;
